package cn.com.wxd.service.dispatch.engine;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import cn.com.wxd.common.CharUtil;

/**
 * Title:自定义定时任务引擎Job类，
 * Description:此类实现了自定义任务中脚本的执行
 * 该类使用了BSF的JavaScript引擎执行传入BSF的javascript脚本进行执行
 * 传入参数:script  脚本
 * isrun 是否运行脚本 值true,false
 * <p>
 * Company: Amumu管理平台
 * Copyright: Copyright (c) 2016
 * All right reserved.
 * Created time: 2017-2-24 上午11:41:51
 *
 * @author ComXu
 * @version 2.0
 */
public class QuartzEngineJob implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //获取传入的参数
        JobDataMap jobdata = context.getJobDetail().getJobDataMap();
        String script = String.valueOf(jobdata.get("Script"));
        String taskId = String.valueOf(jobdata.get("TaskId"));
        String taskName = String.valueOf(jobdata.get("TaskName"));
        if (CharUtil.isEmpty(script) || CharUtil.isEmpty(taskId) || CharUtil.isEmpty(taskName)) {
            return;
        }
        TaskRun taskRun = new TaskRun();
        taskRun.run(taskId, taskName, script);
    }

}
